package com.htjx.mall.controllers.region;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.htjx.mall.commons.models.region.Area;
import com.htjx.mall.commons.models.region.City;
import com.htjx.mall.commons.models.region.Province;
import com.htjx.mall.services.RegionService;

@Controller
@RequestMapping("/region")
public class RegionController {

	@Autowired
	private RegionService regionService;
	
	@RequestMapping(produces="application/json", value="/province", method = RequestMethod.GET)
	@ResponseBody
	public List<Province> province(){
		return regionService.selectProvinces();
	}
	
	@RequestMapping(produces="application/json", value="/city", method = RequestMethod.GET)
	@ResponseBody
	public List<City> city(@RequestParam("province") String province){
		return regionService.selectCity(province);
	}
	
	@RequestMapping(produces="application/json", value="/area", method = RequestMethod.GET)
	@ResponseBody
	public List<Area> area(@RequestParam("city") String city){
		return regionService.selectArea(city);
	}
	
}
